package com.itheima.controller;

import com.itheima.common.Result;
import com.itheima.service.UploadService;
import com.itheima.vo.UploadVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 上传控制器
 *
 * @author 13225
 * @date 2023/09/20
 */
@RestController
public class UploadController {
    private final UploadService uploadService;
    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }

    /**
     * 上传
     * @param type 类型
     * @return {@link Result}<{@link UploadVO}>
     */
    @PostMapping("/common/upload")
    public Result<UploadVO> upload(@RequestParam(name = "type") String type, MultipartFile file){
        UploadVO upload = uploadService.upload(file);
        //返回结果
        return Result.success(upload);
    }
}
